

#编码
path = r"C:\Users\Administrator\Desktop\file3.txt"
with open(path, "wb") as f1:
    str = "sunck is a good man"
    f1.write(str.encode("utf-8"))


#解码
with open(path, "rb") as f2:
    data = f2.read()
    print(data)
    print(type(data))
    newData = data.decode("utf-8")
    print(newData)
    print(type(newData))


#非要用不同类型编码

#编码
path1 = r"C:\Users\Administrator\Desktop\file4.txt"
with open(path1, "w",encoding = "utf-8") as f3:
    str1 = "sunck is a good man我"
    f3.write(str1.encode("utf-8"))


#解码
with open(path1, "r",errors="ignore") as f4:
    data = f4.read()
    print(data)
    print(type(data))